<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>汇率兑换程序</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            background-color: #f0f2f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #1a73e8;
            text-align: center;
            margin-bottom: 30px;
        }
        .input-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            color: #5f6368;
        }
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #dadce0;
            border-radius: 5px;
            font-size: 16px;
        }
        button {
            background: #1a73e8;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
            transition: background 0.3s;
        }
        button:hover {
            background: #1557b0;
        }
        #result {
            margin-top: 25px;
            padding: 15px;
            background: #e8f0fe;
            border-radius: 5px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>美元人民币汇率转换器 (1 USD = 7.0 CNY)</h1>
        
        <div class="input-group">
            <label for="amount">输入金额：</label>
            <input type="number" id="amount" step="0.01" placeholder="请输入金额">
        </div>

        <div class="input-group">
            <label for="currency">选择货币类型：</label>
            <select id="currency">
                <option value="USD">美元 (USD)</option>
                <option value="CNY">人民币 (CNY)</option>
            </select>
        </div>

        <button onclick="convertCurrency()">立即转换</button>

        <div id="result"></div>
    </div>

    <script>
        const EXCHANGE_RATE = 7.0;

        function convertCurrency() {
            // 获取用户输入
            const amountInput = document.getElementById('amount');
            const currencySelect = document.getElementById('currency');
            const resultDiv = document.getElementById('result');

            // 验证输入有效性
            if (!amountInput.value || isNaN(amountInput.value)) {
                alert("请输入有效金额");
                return;
            }

            const amount = parseFloat(amountInput.value);
            const currency = currencySelect.value;

            // 执行转换计算
            let convertedAmount, targetCurrency;
            if (currency === 'USD') {
                convertedAmount = amount * EXCHANGE_RATE;
                targetCurrency = 'CNY';
            } else {
                convertedAmount = amount / EXCHANGE_RATE;
                targetCurrency = 'USD';
            }

            // 显示结果
            resultDiv.innerHTML = `
                <h3>转换结果：</h3>
                <p>${amount.toFixed(2)} ${currency} = ${convertedAmount.toFixed(2)} ${targetCurrency}</p>
                <p>继续操作请修改数值或选择货币类型后再次点击转换</p>
            `;
            resultDiv.style.display = 'block';

            // 清空输入框并保持焦点
            amountInput.value = '';
            amountInput.focus();
        }
    </script>
</body>
</html>
